package sort;

import org.junit.Test;

/**
 * 冒泡排序
 *
 * 挨着的两两相比，交换位置
 */
public class paixu {

    @Test
    public  void test(){
        int[] test ={12,32,1,34,4,66,55,6,5,6,66,88,66};
        for(int i=0;i<test.length-1;i++){
            for (int j =0;j<test.length-i-1;j++){
                if(test[j] > test[j+1]){
                    int d =  test[j];
                    test[j] =  test[j+1];
                    test[j+1] =d;
                }
            }
        }
        for(int i = 0;i<test.length;i++){
            System.out.println(test[i]);
        }
    }
    //    选择排序
//    依次选择最大的那个
    @Test
    public  void test2(){
        int[] test ={12,32,1,34,4,66,55,6,5,6,66,88,66};
        for(int i=0;i<test.length;i++){
            for (int j =i+1;j<test.length;j++){
                if(test[i] < test[j]){
                    int d =  test[j];
                    test[j] =  test[i];
                    test[i] =d;
                }
            }
        }
        for(int i = 0;i<test.length;i++){
            System.out.println(test[i]);
        }
    }
}
